/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ywk.openFeignServer1.provider;

import com.ywk.openFeignApi.User;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
public class EchoServiceController {

    @GetMapping("/echo/{message}")
    public String echo(@PathVariable String message, HttpServletRequest request) {
        System.out.println(request.getHeader(HttpHeaders.AUTHORIZATION));
        return "[ECHO] : " + message;
    }

    @GetMapping("/select")
    public User select(@RequestParam Integer id,@RequestParam String name) {
        User user = new User();
        user.setId(id);
        user.setName(name);
        return user;
    }

    /**
     *
     * @param user
     * @return
     */
    @GetMapping(value = "/selectList")
    public List<User> selectList(/*@RequestBody*/ User user) {//提供消费接口时不能用@RequestBody修饰
        System.out.println(user);
        ArrayList<User> users = new ArrayList<>();
        User user1 = new User();
        user1.setId(1);
        user1.setName("11");
        User user2 = new User();
        user2.setId(2);
        user2.setName("22");
        users.add(user);
        users.add(user1);
        users.add(user2);
        return users;
    }

    @PostMapping(value = "/getStr" )
    public String create(String str) {
        System.out.println(str);
        return str+"1";
    }

    @PostMapping(value = "/create", consumes = "application/json")
    public User create(@RequestBody User user) {
        System.out.println(user);
        return user;
    }
}
